Skip to content

Bit Manipulation

Alt text

LabelOpcodeOperandExplanation
AND#n/Bn/&nBitwise AND operation of the contents of ACC with the operand
AND<address>Bitwise AND operation of the contents of ACC with the contents of <address>
XOR#n/Bn/&nBitwise XOR operation of the contents of ACC with the operand
XOR<address>Bitwise XOR operation of the contents of ACC with the contents of <address>
OR#n/Bn/&nBitwise OR operation of the contents of ACC with the operand
OR<address>Bitwise OR operation of the contents of ACC with the contents of <address>
LSL#nBits in ACC are shifted logically n places to the left. Zeros are introduced on the right hand end
LSR#nBits in ACC are shifted logically n places to the right. Zeros are introduced on the left hand end
<label>:<opcode><operand>Labels an instruction
<label>:<data>Gives a symbolic address <label> to the memory location with contents <data>

TIP

  • All questions will assume there is only one general purpose register available (Accumulator) ACC denotes Accumulator
  • IX denotes Index Register
  • <address> can be an absolute or symbolic address
  • # denotes a denary number, e.g. #123
  • B denotes a binary number, e.g. B01001010 & denotes a hexadecimal number, e.g. &4A
  • ## Binary shifts
  • Logical shift – bits shifted out of the register are replaced with zeros.
  • Arithmetic shift – the sign of the number is preserved.
  • Cyclic shift –Bits shifted out of one end of the register are introduced at the other end of the register.
  • Left shift – bits are shifted to the left; gives the direction of shift for logical, arithmetic and cyclic shifts.
  • Right shift – bits are shifted to the right; gives the direction of shift for logical, arithmetic and cyclic shifts.
OpcodeOperandExplanation
LSLnBits in ACC are shifted logically n places to the left. Zeros are introduced on the right hand end
LSRnBits in ACC are shifted logically n places to the right. Zeros are introduced on the left hand end

TIP

Shifts are always performed on the ACC

Bit manipulation used in monitoring and control

In monitoring and control, each bit in a register or memory location can be used as a flag and would need to be tested, set or cleared separately.

  • AND is used to check if the bit has been set.
  • OR is used to set the bit.
  • XOR is used to clear a bit that has been set.
OpcodeOperandExplanation
ANDnBitwise AND operation of the contents of ACC with the operand
AND<address>Bitwise AND operation of the contents of ACC with the contents of <address>
XORnBitwise XOR operation of the contents of ACC with the operand
XOR<address>Bitwise XOR operation of the contents of ACC with the contents of <address>
ORnBitwise OR operation of the contents of ACC with the operand
OR<address>Bitwise OR operation of the contents of ACC with the contents of <address>

TIP

  • The results of logical bit manipulation are always stored in the ACC.
  • <address> can be anabsolute address or a symbolic address.
  • The operand is used as the mask to set or clear bits.

Bit operation

State the contents of the accumulator after the following instructions have been executed. The accumulator contains 00011001.

  • LSL #4 (ACC:)
  • LSR #5 (ACC:)
[0/2]

Bit operation

Write an assembly language instruction to

  • set bit 4 in the accumulator ()
  • clear bit 1 in the accumulator ()
[0/2]